{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Project: Fast Solvers for Stokes Equations\n",
    "\n",
    "The purpose of this project is to implement fast solvers for solving\n",
    "finite element and finite difference discretization of Stokes equations."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Part I: Block Preconditioner\n",
    "\n",
    "Given a triangulation, use codes in [Project: Finite Element Methods for Stokes Equation](projectStokes.html) to generate matrices for isoP2-P0 and P1CR-P0 for Stokes equations. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 1: Direct solvers in preconditioner \n",
    "\n",
    "Use $\\begin{pmatrix} A^{-1} & 0\\\\ 0 & Mp^{-1}\\end{pmatrix}$ as the preconditioner and call `minres`.\n",
    "\n",
    "Do not use `inv(A)` to form the inverse. Instead the preconditioner can be coded as a subroutine and use backslash to invert `A`. \n",
    "\n",
    "For isoP2-P0 and P1CR-P0, the mass matrix for pressure is a diagonal\n",
    "matrix. The inverse of Mp can be realized by a vector multiplication.\n",
    "\n",
    "Refine the triangulation several times and list the iteration steps of\n",
    "`minres` and cpu time. The steps should be uniform but the time may not be\n",
    "linearly scaled due to the direct solver used in the preconditioner. Use\n",
    "`showrate` to check the scaling of cpu time vs size of problems."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 2: Replace direct solver by multigrid solver\n",
    "\n",
    "The direct solver of `A` can be replaced by multigrid solvers included in\n",
    "ifem. Try `help mg` or `help amg`.\n",
    "\n",
    "To use `mg`, the mesh structure `elem` should be provided. So you need to\n",
    "modify the matrices to build in the Dirichlet boundary condition. If you\n",
    "only take out submatrices associated to free dofs, you can use `amg`.\n",
    "\n",
    "Redo the test in step 1. You should get the same iteration steps and now\n",
    "the cpu time scales linearly. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Step 3: Replace exact multigrid solver by V-cycles\n",
    "\n",
    "Set `option.maxIt = 3` and redo the test. The iteration steps could\n",
    "increase but cpu time is saved instead. How about `option.maxIt = 1`?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Part II: Block-triangular Preconditoner\n",
    "\n",
    "Use $\\begin{pmatrix}A & B'\\\\ 0 & -Mp \\end{pmatrix}^{-1}$ as the preconditioner and call `gmres`.\n",
    "\n",
    "Repeat three steps in Part I and compare the cpu time for these two preconditioners."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Matlab",
   "language": "matlab",
   "name": "matlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "help_links": [
    {
     "text": "MetaKernel Magics",
     "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
    }
   ],
   "mimetype": "text/x-matlab",
   "name": "matlab",
   "version": "0.14.3"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "192px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": false,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": true,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
